home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / Onboard / Config.py next >
Text File  |  2009-10-01  |  25KB  |  753 lines

  1. """
  2. File containing Config singleton.
  3. """
  4.  
  5. ### Logging ###
  6. import logging
  7. _logger = logging.getLogger("Config")
  8. ###############
  9.  
  10. import gconf
  11. import os
  12. import sys
  13.  
  14. from optparse import OptionParser
  15.  
  16. KEYBOARD_WIDTH_GCONF_KEY    = "/apps/onboard/width"
  17. KEYBOARD_HEIGHT_GCONF_KEY   = "/apps/onboard/height"
  18. LAYOUT_FILENAME_GCONF_KEY   = "/apps/onboard/layout_filename"
  19. X_POSITION_GCONF_KEY        = "/apps/onboard/horizontal_position"
  20. Y_POSITION_GCONF_KEY        = "/apps/onboard/vertical_position"
  21. SCANNING_GCONF_KEY          = "/apps/onboard/enable_scanning"
  22. SCANNING_INTERVAL_GCONF_KEY = "/apps/onboard/scanning_interval"
  23. SNIPPETS_GCONF_KEY          = "/apps/onboard/snippets"
  24. SHOW_TRAYICON_GCONF_KEY     = "/apps/onboard/use_trayicon"
  25. START_MINIMIZED_GCONF_KEY   = "/apps/onboard/start_minimized"
  26.  
  27. KEYBOARD_DEFAULT_HEIGHT   = 800
  28. KEYBOARD_DEFAULT_WIDTH    = 300
  29.  
  30. SCANNING_DEFAULT_INTERVAL = 750
  31.  
  32. GTK_KBD_MIXIN_MOD = "Onboard.KeyboardGTK"
  33. GTK_KBD_MIXIN_CLS = "KeyboardGTK"
  34.  
  35. INSTALL_DIR = "/usr/share/onboard"
  36.  
  37. ICP_IN_USE_GCONF_KEY     = "/apps/onboard/icon_palette/in_use"
  38. ICP_WIDTH_GCONF_KEY      = "/apps/onboard/icon_palette/width"
  39. ICP_HEIGHT_GCONF_KEY     = "/apps/onboard/icon_palette/height"
  40. ICP_X_POSITION_GCONF_KEY = "/apps/onboard/icon_palette/horizontal_position"
  41. ICP_Y_POSITION_GCONF_KEY = "/apps/onboard/icon_palette/vertical_position"
  42.  
  43. ICP_DEFAULT_HEIGHT   = 80
  44. ICP_DEFAULT_WIDTH    = 80
  45. ICP_DEFAULT_X_POSITION = 40
  46. ICP_DEFAULT_Y_POSITION = 300
  47.  
  48. class Config (object):
  49.     """
  50.     Singleton Class to encapsulate the gconf stuff and check values.
  51.     """
  52.  
  53.     _gconf_client = gconf.client_get_default()
  54.  
  55.     _kbd_render_mixin_mod = GTK_KBD_MIXIN_MOD
  56.     """ 
  57.     String representation of the module containing the Keyboard mixin
  58.     used to draw keyboard
  59.     """
  60.  
  61.     _kbd_render_mixin_cls = GTK_KBD_MIXIN_CLS
  62.     """ 
  63.     String representation of the keyboard mixin used to draw keyboard.
  64.     """
  65.  
  66.     _set_height = None
  67.     """ Height when set on cmd line """
  68.  
  69.     _set_width = None
  70.     """ Width when set on cmd line """
  71.  
  72.     _old_snippets = None
  73.     """
  74.     A copy of snippets so that when the list changes in gconf we can tell which
  75.     items have changed.
  76.     """
  77.  
  78.     SIDEBARWIDTH = 60
  79.     """ Width of sidebar buttons """
  80.  
  81.     DEFAULT_LABEL_OFFSET = (2.0, 0.0)
  82.     """ Offset of label from key edge when not specified in layout"""
  83.  
  84.     LABEL_MARGIN = (4,0)
  85.     """ Margin to leave around labels """
  86.  
  87.     def __new__(cls, *args, **kwargs): 
  88.         """
  89.         Singleton magic.
  90.         """
  91.         if not hasattr(cls, "self"):
  92.             cls.self = object.__new__(cls)
  93.             cls.self._init()
  94.         return cls.self
  95.  
  96.     def _init(self):
  97.         """
  98.         Singleton constructor, should only run once.
  99.         """
  100.         _logger.debug("Entered in _init")
  101.  
  102.         parser = OptionParser()
  103.         parser.add_option("-l", "--layout", dest="filename",
  104.                 help="Specify layout .sok file")
  105.         parser.add_option("-x", type="int", dest="x", help="x coord of window")
  106.         parser.add_option("-y", type="int", dest="y", help="y coord of window")
  107.         parser.add_option("-s", "--size", dest="size",
  108.                 help="size widthxheight")
  109.         parser.add_option("-d", "--debug", type="str", dest="debug",
  110.             help="DEBUG={notset|debug|info|warning|error|critical}")
  111.         options = parser.parse_args()[0]
  112.  
  113.         if options.debug:
  114.             logging.basicConfig(level=getattr(logging, options.debug.upper()))
  115.         else:
  116.             logging.basicConfig()
  117.  
  118.         self._gconf_client.add_dir("/apps/onboard", gconf.CLIENT_PRELOAD_NONE)
  119.         self._gconf_client.notify_add(KEYBOARD_WIDTH_GCONF_KEY,
  120.                 self._geometry_notify_cb)
  121.         self._gconf_client.notify_add(KEYBOARD_HEIGHT_GCONF_KEY, 
  122.                 self._geometry_notify_cb)
  123.  
  124.         self._gconf_client.notify_add(ICP_IN_USE_GCONF_KEY,
  125.                 self._icp_in_use_change_notify_cb)
  126.         self._gconf_client.notify_add(ICP_WIDTH_GCONF_KEY,
  127.                 self._icp_size_change_notify_cb)
  128.         self._gconf_client.notify_add(ICP_HEIGHT_GCONF_KEY,
  129.                 self._icp_size_change_notify_cb)
  130.         self._gconf_client.notify_add(ICP_X_POSITION_GCONF_KEY,
  131.                 self._icp_position_change_notify_cb)
  132.         self._gconf_client.notify_add(ICP_Y_POSITION_GCONF_KEY,
  133.                 self._icp_position_change_notify_cb)
  134.         self._gconf_client.notify_add(START_MINIMIZED_GCONF_KEY,
  135.                 self._start_minimized_notify_cb)
  136.         self._gconf_client.notify_add(SNIPPETS_GCONF_KEY,
  137.                 self._snippets_notify_cb)
  138.  
  139.         self._old_snippets = self.snippets
  140.         
  141.         if (options.size):
  142.             size = options.size.split("x")
  143.             self._set_width  = int(size[0])
  144.             self._set_height = int(size[1])
  145.  
  146.         if (options.x):
  147.             self.x_position = int(options.x)
  148.         if (options.y):
  149.             self.y_position = int(options.y)
  150.  
  151.         # Find layout
  152.         if options.filename:
  153.             filename = options.filename
  154.         else:
  155.             filename = self._gconf_client.get_string(LAYOUT_FILENAME_GCONF_KEY)
  156.  
  157.         if filename and not os.path.exists(filename):
  158.             _logger.warning("Can't load %s loading default layout instead" %
  159.                 filename)
  160.             filename = ''
  161.  
  162.         if not filename:
  163.             filename = os.path.join(self.install_dir,
  164.                     "layouts", "Default.sok")
  165.  
  166.         if not os.path.exists(filename):
  167.             raise Exception("Unable to find layout %s" % filename)
  168.         self.__filename = filename
  169.  
  170.         self._gconf_client.notify_add(LAYOUT_FILENAME_GCONF_KEY,
  171.                 self._layout_filename_notify_cb)
  172.         self._gconf_client.notify_add(X_POSITION_GCONF_KEY,
  173.                 self._position_notify_cb)
  174.         self._gconf_client.notify_add(Y_POSITION_GCONF_KEY,
  175.                 self._position_notify_cb)
  176.         self._gconf_client.notify_add(SCANNING_GCONF_KEY,
  177.                 self._scanning_notify_cb)
  178.         self._gconf_client.notify_add(SCANNING_INTERVAL_GCONF_KEY,
  179.                 self._scanning_interval_notify_cb)
  180.         self._gconf_client.notify_add(SHOW_TRAYICON_GCONF_KEY,
  181.                 self._show_trayicon_notify_cb)
  182.  
  183.         _logger.debug("Leaving _init")
  184.  
  185.     ######## Layout #########
  186.     _layout_filename_notify_callbacks   = []
  187.     def layout_filename_notify_add(self, callback):
  188.         """
  189.         Register callback to be run when layout filename changes.
  190.  
  191.         Callbacks are called with the layout filename as a parameter.
  192.  
  193.         @type  callback: function
  194.         @param callback: callback to call on change
  195.         """
  196.         self._layout_filename_notify_callbacks.append(callback)
  197.  
  198.     def _layout_filename_notify_cb(self, client, cxion_id, entry, user_data):
  199.         """
  200.         Recieve layout change notifications from gconf and check the file is
  201.         valid before calling callbacks.
  202.         """
  203.         filename = self._gconf_client.get_string(LAYOUT_FILENAME_GCONF_KEY)
  204.         if not os.path.exists(filename):
  205.             _logger.warning("layout %s does not exist" % filename)
  206.         else:
  207.             self.__filename = filename
  208.  
  209.         for callback in self._layout_filename_notify_callbacks:
  210.             callback(filename)
  211.  
  212.     def _get_layout_filename(self):
  213.         """
  214.         Layout filename getter.
  215.         """
  216.         return self.__filename
  217.     def _set_layout_filename(self, value):
  218.         """
  219.         Layout filename setter, TODO check valid.
  220.  
  221.         @type  value: str
  222.         @param value: Absolute path to the layout description file.
  223.         """
  224.         self._gconf_client.set_string(LAYOUT_FILENAME_GCONF_KEY, value)
  225.     layout_filename = property(_get_layout_filename, _set_layout_filename)
  226.  
  227.     ####### Geometry ########
  228.     _geometry_notify_callbacks = []
  229.     def _get_keyboard_height(self):
  230.         """
  231.         Keyboard height getter, check height is greater than 1.
  232.         """
  233.         if self._set_height:
  234.             height = self._set_height
  235.         else:
  236.             height = self._gconf_client.get_int(KEYBOARD_HEIGHT_GCONF_KEY)
  237.  
  238.         if height and height > 1:
  239.             return height
  240.         else:
  241.             return KEYBOARD_DEFAULT_HEIGHT
  242.     def _set_keyboard_height(self, value):
  243.         """
  244.         Keyboard height setter, check height is greater than 1.
  245.         """
  246.         if value > 1 and \
  247.            value != self._gconf_client.get_int(KEYBOARD_HEIGHT_GCONF_KEY):
  248.             self._gconf_client.set_int(KEYBOARD_HEIGHT_GCONF_KEY, value)
  249.     keyboard_height = property(_get_keyboard_height, _set_keyboard_height)
  250.  
  251.     def _get_keyboard_width(self):
  252.         """
  253.         Keyboard width getter, check width is greater than 1.
  254.         """
  255.         if self._set_width:
  256.             width = self._set_width
  257.         else:
  258.             width = self._gconf_client.get_int(KEYBOARD_WIDTH_GCONF_KEY)
  259.  
  260.         if width and width > 1:
  261.             return width
  262.         else:
  263.             return KEYBOARD_DEFAULT_WIDTH
  264.     def _set_keyboard_width(self, value):
  265.         """
  266.         Keyboard width setter, check width is greater than 1.
  267.         """
  268.         if value > 1 and \
  269.                 value != self._gconf_client.get_int(KEYBOARD_WIDTH_GCONF_KEY):
  270.             self._gconf_client.set_int(KEYBOARD_WIDTH_GCONF_KEY, value)
  271.     keyboard_width  = property(_get_keyboard_width, _set_keyboard_width)
  272.  
  273.     def geometry_notify_add(self, callback):
  274.         """
  275.         Register callback to be run when the keyboard geometry changes.
  276.  
  277.         Callbacks are called with the new geomtery as a parameter.
  278.  
  279.         @type  callback: function
  280.         @param callback: callback to call on change
  281.         """
  282.         self._geometry_notify_callbacks.append(callback)
  283.  
  284.     def _geometry_notify_cb(self, client, cxion_id, entry, user_data):
  285.         """
  286.         Recieve geometry change notifications from gconf and run callbacks.
  287.         """
  288.         for callback in self._geometry_notify_callbacks:
  289.             callback(self.keyboard_width, self.keyboard_height)
  290.  
  291.     ####### Position ########
  292.     _position_notify_callbacks = []
  293.     def _get_x_position(self):
  294.         """
  295.         Keyboard x position getter.
  296.         """
  297.         return self._gconf_client.get_int(X_POSITION_GCONF_KEY)
  298.     def _set_x_position(self, value):
  299.         """
  300.         Keyboard x position setter.
  301.         """
  302.         if value + self.keyboard_width > 1 and \
  303.                 value != self._gconf_client.get_int(X_POSITION_GCONF_KEY):
  304.             _logger.info("New keyboard x position: %d" % value)
  305.             self._gconf_client.set_int(X_POSITION_GCONF_KEY, value)
  306.     x_position = property(_get_x_position, _set_x_position)
  307.  
  308.     def _get_y_position(self):
  309.         """
  310.         Keyboard y position getter.
  311.         """
  312.         return self._gconf_client.get_int(Y_POSITION_GCONF_KEY)
  313.     def _set_y_position(self, value):
  314.         """
  315.         Keyboard y position setter.
  316.         """
  317.         if value + self.keyboard_height > 1 and \
  318.            value != self._gconf_client.get_int(Y_POSITION_GCONF_KEY):
  319.             self._gconf_client.set_int(Y_POSITION_GCONF_KEY, value)
  320.     y_position = property(_get_y_position, _set_y_position)
  321.  
  322.     def position_notify_add(self, callback):
  323.         """
  324.         Register callback to be run when the keyboard position changes.
  325.  
  326.         Callbacks are called with the new position as a parameter.
  327.  
  328.         @type  callback: function
  329.         @param callback: callback to call on change
  330.         """
  331.         self._position_notify_callbacks.append(callback)
  332.  
  333.     def _position_notify_cb(self, client, cxion_id, entry, user_data):
  334.         """
  335.         Recieve position change notifications from gconf and run callbacks.
  336.         """
  337.         for callback in self._position_notify_callbacks:
  338.             callback(self.x_position, self.y_position)
  339.  
  340.     ####### Scanning ########
  341.     _scanning_callbacks = []
  342.     def _get_scanning(self):
  343.         """
  344.         Scanning mode active getter.
  345.         """
  346.         return self._gconf_client.get_bool(SCANNING_GCONF_KEY)
  347.     def _set_scanning(self, value):
  348.         """
  349.         Scanning mode active setter.
  350.         """
  351.         return self._gconf_client.set_bool(SCANNING_GCONF_KEY, value)
  352.     scanning = property(_get_scanning, _set_scanning)
  353.  
  354.     def scanning_notify_add(self, callback):
  355.         """
  356.         Register callback to be run when the scanning mode changes.
  357.  
  358.         Callbacks are called with the new value as a parameter.
  359.  
  360.         @type  callback: function
  361.         @param callback: callback to call on change
  362.         """
  363.         self._scanning_callbacks.append(callback)
  364.  
  365.     def _scanning_notify_cb(self, client, cxion_id, entry, user_data):
  366.         """
  367.         Recieve scanning mode change notifications from gconf and run callbacks.
  368.         """
  369.         for callback in self._scanning_callbacks:
  370.             callback(self.scanning)
  371.  
  372.     ## Scanning interval ####
  373.     _scanning_interval_callbacks = []
  374.     def _get_scanning_interval(self):
  375.         """
  376.         Scanning interval time getter.
  377.         """
  378.         interval = self._gconf_client.get_int(SCANNING_INTERVAL_GCONF_KEY)
  379.         if interval and interval > 0:
  380.             return interval
  381.         else:
  382.             return SCANNING_DEFAULT_INTERVAL
  383.     def _set_scanning_interval(self, value):
  384.         """
  385.         Scanning interval time getter.
  386.         """
  387.         return self._gconf_client.set_int(SCANNING_INTERVAL_GCONF_KEY, value)
  388.     scanning_interval = property(_get_scanning_interval, _set_scanning_interval)
  389.  
  390.     def scanning_interval_notify_add(self, callback):
  391.         """
  392.         Register callback to be run when the scanning interval time changes.
  393.  
  394.         Callbacks are called with the new time as a parameter.
  395.  
  396.         @type  callback: function
  397.         @param callback: callback to call on change
  398.         """
  399.         self._scanning_interval_callbacks.append(callback)
  400.  
  401.     def _scanning_interval_notify_cb(self, client, cxion_id, entry, 
  402.             user_data):
  403.         """
  404.         Recieve scanning interval change notifications from gconf and run
  405.         callbacks.
  406.         """
  407.         for callback in self._scanning_interval_callbacks:
  408.             callback(self.scanning_interval)
  409.  
  410.     ####### Snippets #######
  411.     _snippet_callbacks = []
  412.     _snippets_callbacks = []
  413.     def _get_snippets(self):
  414.         """
  415.         List of snippets getter.
  416.         """
  417.         return self._gconf_client.get_list(SNIPPETS_GCONF_KEY,
  418.                 gconf.VALUE_STRING)
  419.     def _set_snippets(self, value):
  420.         """
  421.         List of snippets setter.
  422.         """
  423.         self._gconf_client.set_list(SNIPPETS_GCONF_KEY, gconf.VALUE_STRING,
  424.                 value)
  425.     snippets = property(_get_snippets, _set_snippets)
  426.  
  427.     def set_snippet(self, index, value):
  428.         """
  429.         Set a snippet in the snippet list.  Enlarge the list if not big
  430.         enough.
  431.  
  432.         @type  index: int
  433.         @param index: index of the snippet to set.
  434.         @type  value: str
  435.         @param value: Contents of the new snippet.
  436.         """
  437.         if value == None:
  438.             raise TypeError("Snippet text must be str")
  439.  
  440.         snippets = self.snippets
  441.         for n in range(1 + index - len(snippets)):
  442.             snippets.append("")
  443.         _logger.info("Setting snippet %d to %s" % (index, value))
  444.         snippets[index] = value
  445.         self.snippets = snippets
  446.  
  447.     def del_snippet(self, index):
  448.         _logger.info("Deleting snippet %d" % index)
  449.         snippets = self.snippets
  450.         snippets[index] = ""
  451.         self.snippets = snippets
  452.  
  453.     def snippet_notify_add(self, callback):
  454.         """
  455.         Register callback to be run for each snippet that changes
  456.  
  457.         Callbacks are called with the snippet index as a parameter.
  458.  
  459.         @type  callback: function
  460.         @param callback: callback to call on change
  461.         """
  462.         self._snippet_callbacks.append(callback)
  463.  
  464.     def snippets_notify_add(self, callback):
  465.         """
  466.         Register callback to be run when the snippets list changes.
  467.  
  468.         Callbacks are called with the new list as a parameter.
  469.  
  470.         @type  callback: function
  471.         @param callback: callback to call on change
  472.         """
  473.         self._snippets_callbacks.append(callback)
  474.  
  475.     def _snippets_notify_cb(self, client, cxion_id, entry, user_data):
  476.         """
  477.         Recieve snippets list notifications from gconf and run callbacks.
  478.         """
  479.         snippets = self.snippets
  480.  
  481.         for callback in self._snippets_callbacks:
  482.             callback(snippets)
  483.  
  484.         
  485.         # If the snippets in the two lists don't have the same value or one
  486.         # list has more items than the other do callbacks for each item that
  487.         # differs
  488.  
  489.         length_of_shortest = min(len(snippets), len(self._old_snippets))
  490.         length_of_longest = max(len(snippets), len(self._old_snippets))
  491.         for index in range(length_of_shortest):
  492.             if snippets[index] != self._old_snippets[index]:
  493.                 for callback in self._snippet_callbacks:
  494.                     callback(index)
  495.  
  496.         for index in range(length_of_shortest, length_of_longest):
  497.             for callback in self._snippet_callbacks:
  498.                 callback(index)
  499.  
  500.         self._old_snippets = self.snippets
  501.  
  502.  
  503.     ####### Trayicon #######
  504.     _show_trayicon_callbacks = []
  505.     def _get_show_trayicon(self):
  506.         """
  507.         Trayicon visible getter.
  508.         """
  509.         return self._gconf_client.get_bool(SHOW_TRAYICON_GCONF_KEY)
  510.     def _set_show_trayicon(self, value):
  511.         """
  512.         Trayicon visible setter.
  513.         """
  514.         return self._gconf_client.set_bool(SHOW_TRAYICON_GCONF_KEY, value)
  515.     show_trayicon = property(_get_show_trayicon, _set_show_trayicon)
  516.  
  517.     def show_trayicon_notify_add(self, callback):
  518.         """
  519.         Register callback to be run when the trayicon visibility changes.
  520.  
  521.         Callbacks are called with the new list as a parameter.
  522.  
  523.         @type  callback: function
  524.         @param callback: callback to call on change
  525.         """
  526.         self._show_trayicon_callbacks.append(callback)
  527.  
  528.     def _show_trayicon_notify_cb(self, client, cxion_id, entry, 
  529.             user_data):
  530.         """
  531.         Recieve trayicon visibility notifications from gconf and run callbacks.
  532.         """
  533.         for callback in self._show_trayicon_callbacks:
  534.             callback(self.show_trayicon)
  535.  
  536.     #### Start minimized ####
  537.     _start_minimized_callbacks = []
  538.     def _get_start_minimized(self):
  539.         """
  540.         Start minimized getter.
  541.         """
  542.         return self._gconf_client.get_bool(START_MINIMIZED_GCONF_KEY)
  543.     def _set_start_minimized(self, value):
  544.         """
  545.         Start minimized setter.
  546.         """
  547.         return self._gconf_client.set_bool(START_MINIMIZED_GCONF_KEY, value)
  548.     start_minimized = property(_get_start_minimized, _set_start_minimized)
  549.  
  550.     def start_minimized_notify_add(self, callback):
  551.         """
  552.         Register callback to be run when the start minimized option changes.
  553.  
  554.         Callbacks are called with the new list as a parameter.
  555.  
  556.         @type  callback: function
  557.         @param callback: callback to call on change
  558.         """
  559.         self._start_minimized_callbacks.append(callback)
  560.  
  561.     def _start_minimized_notify_cb(self, client, cxion_id, entry, 
  562.             user_data):
  563.         """
  564.         Recieve trayicon visibility notifications from gconf and run callbacks.
  565.         """
  566.         for callback in self._start_minimized_callbacks:
  567.             callback(self.start_minimized)
  568.  
  569.     def _get_kbd_render_mixin(self):
  570.         __import__(self._kbd_render_mixin_mod)
  571.         return getattr(sys.modules[self._kbd_render_mixin_mod],
  572.                 self._kbd_render_mixin_cls)
  573.     kbd_render_mixin = property(_get_kbd_render_mixin)
  574.  
  575.     def _get_install_dir(self):
  576.         # ../Config.py
  577.         path = os.path.dirname(
  578.             os.path.dirname(os.path.abspath(__file__)))
  579.  
  580.         # when run uninstalled
  581.         if os.path.isfile(os.path.join(path, "data", "onboard.svg")):
  582.             return path
  583.         # when installed
  584.         elif os.path.isdir(INSTALL_DIR):
  585.             return INSTALL_DIR
  586.     install_dir = property(_get_install_dir)
  587.  
  588.  
  589.     ####### IconPalette aka icp ########
  590.  
  591.     # iconPalette activation option
  592.     def _icp_get_in_use(self):
  593.         """
  594.         iconPalette visible getter.
  595.         """
  596.         return self._gconf_client.get_bool(ICP_IN_USE_GCONF_KEY)
  597.  
  598.     def _icp_set_in_use(self, value):
  599.         """
  600.         iconPalette visible setter.
  601.         """
  602.         return self._gconf_client.set_bool(ICP_IN_USE_GCONF_KEY, value)
  603.  
  604.     icp_in_use = property(_icp_get_in_use, _icp_set_in_use)
  605.  
  606.     # callback for when the iconPalette gets activated/deactivated
  607.     _icp_in_use_change_callbacks = []
  608.  
  609.     def icp_in_use_change_notify_add(self, callback):
  610.         """
  611.         Register callback to be run when the setting about using
  612.         the IconPalette changes.
  613.  
  614.         Callbacks are called with the new list as a parameter.
  615.  
  616.         @type  callback: function
  617.         @param callback: callback to call on change
  618.         """
  619.         self._icp_in_use_change_callbacks.append(callback)
  620.  
  621.     def _icp_in_use_change_notify_cb(self, client, cxion_id, entry, user_data):
  622.         """
  623.         Recieve iconPalette visibility notifications from gconf and run callbacks.
  624.         """
  625.         for callback in self._icp_in_use_change_callbacks:
  626.             callback(self.icp_in_use)
  627.  
  628.  
  629.     # iconPalette size
  630.     def _icp_get_width(self):
  631.         """
  632.         iconPalette width getter.
  633.         """
  634.         width = self._gconf_client.get_int(ICP_WIDTH_GCONF_KEY)
  635.         if width:
  636.             return width
  637.         else:
  638.             return ICP_DEFAULT_WIDTH
  639.  
  640.     def _icp_set_width(self, value):
  641.         """
  642.         iconPalette width setter.
  643.         """
  644.         if value > 0 and \
  645.            value != self._gconf_client.get_int(ICP_WIDTH_GCONF_KEY):
  646.             self._gconf_client.set_int(ICP_WIDTH_GCONF_KEY, int(value))
  647.  
  648.     icp_width  = property(_icp_get_width, _icp_set_width)
  649.  
  650.     def _icp_get_height(self):
  651.         """
  652.         iconPalette height getter.
  653.         """
  654.         height = self._gconf_client.get_int(ICP_HEIGHT_GCONF_KEY)
  655.         if height:
  656.             return height
  657.         else:
  658.             return ICP_DEFAULT_HEIGHT
  659.  
  660.     def _icp_set_height(self, value):
  661.         """
  662.         iconPalette height setter.
  663.         """
  664.         if value > 0 and \
  665.            value != self._gconf_client.get_int(ICP_HEIGHT_GCONF_KEY):
  666.             self._gconf_client.set_int(ICP_HEIGHT_GCONF_KEY, int(value))
  667.  
  668.     icp_height = property(_icp_get_height, _icp_set_height)
  669.  
  670.     _icp_size_change_notify_callbacks = []
  671.  
  672.     def icp_size_change_notify_add(self, callback):
  673.         """
  674.         Register callback to be run when the size of the iconPalette
  675.         changes.
  676.  
  677.         Callbacks are called with the new size as a parameter.
  678.  
  679.         @type  callback: function
  680.         @param callback: callback to call on change
  681.         """
  682.         self._icp_size_change_notify_callbacks.append(callback)
  683.  
  684.     def _icp_size_change_notify_cb(self, client, cxion_id, entry, user_data):
  685.         """
  686.         Recieve size change notifications from gconf and run callbacks.
  687.         """
  688.         for callback in self._icp_size_change_notify_callbacks:
  689.             callback(self.icp_width, self.icp_height)
  690.  
  691.  
  692.     # iconPalette position
  693.     def _icp_get_x_position(self):
  694.         """
  695.         iconPalette x position getter.
  696.         """
  697.         x_pos = self._gconf_client.get_int(ICP_X_POSITION_GCONF_KEY)
  698.         if x_pos:
  699.             return x_pos
  700.         else:
  701.             return ICP_DEFAULT_X_POSITION
  702.  
  703.     def _icp_set_x_position(self, value):
  704.         """
  705.         iconPalette x position setter.
  706.         """
  707.         if value > 0 and \
  708.            value != self._gconf_client.get_int(ICP_X_POSITION_GCONF_KEY):
  709.             self._gconf_client.set_int(ICP_X_POSITION_GCONF_KEY, int(value))
  710.  
  711.     icp_x_position = property(_icp_get_x_position, _icp_set_x_position)
  712.  
  713.     def _icp_get_y_position(self):
  714.         """
  715.         iconPalette y position getter.
  716.         """
  717.         y_pos = self._gconf_client.get_int(ICP_Y_POSITION_GCONF_KEY)
  718.         if y_pos:
  719.             return y_pos
  720.         else:
  721.             return ICP_DEFAULT_Y_POSITION
  722.  
  723.     def _icp_set_y_position(self, value):
  724.         """
  725.         iconPalette y position setter.
  726.         """
  727.         if value > 0 and \
  728.            value != self._gconf_client.get_int(ICP_Y_POSITION_GCONF_KEY):
  729.             self._gconf_client.set_int(ICP_Y_POSITION_GCONF_KEY, int(value))
  730.  
  731.     icp_y_position = property(_icp_get_y_position, _icp_set_y_position)
  732.  
  733.     _icp_position_change_notify_callbacks = []
  734.  
  735.     def icp_position_change_notify_add(self, callback):
  736.         """
  737.         Register callback to be run when the position of the
  738.         iconPalette changes.
  739.  
  740.         Callbacks are called with the new position as a parameter.
  741.  
  742.         @type  callback: function
  743.         @param callback: callback to call on change
  744.         """
  745.         self._icp_position_change_notify_callbacks.append(callback)
  746.  
  747.     def _icp_position_change_notify_cb(self, client, cxion_id, entry, user_data):
  748.         """
  749.         Recieve position change notifications from gconf and run callbacks.
  750.         """
  751.         for callback in self._icp_position_change_notify_callbacks:
  752.             callback(self.icp_x_position, self.icp_y_position)
  753.